﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpiConsole;
using MinimizeEngine.Managers;
using MinimizeEngine.Menu_System;
using MinimizeEngine.Screens;
using MinimizeEngine.Entities;
using MinimizeEngine.Components.Render;
using Microsoft.Xna.Framework;

namespace MinimizeEngine.Engine_Components.Console
{
    public class Command_RestartDevice : Command
    {
        public Command_RestartDevice() : base("restartDevice", "Restarts the Device (Refreshes Screen Width, etc.)", UsageLevel.NORMAL)
        {

        }

        public override bool Invoke(List<string> args)
        {
            MEEngineManager.Console.Clear();
            return true;
        }
    }

    #if!XBOX360
    public class Command_OpenForm : Command
    {
        public Command_OpenForm()
            : base("openForm", "Opens Scene Graph Form", UsageLevel.NORMAL)
        {

        }

        public override bool Invoke(List<string> args)
        {
            MEEngineManager.CreateForm();
            return true;
        }
    }
    #endif

    public class Command_PlaySong : Command
    {
        public Command_PlaySong()
            : base("playSong", "Play a Song from the Minimize Engine Media Library", UsageLevel.NORMAL)
        {

        }

        public override bool Invoke(List<string> args)
        {
            MEAudioManager.PlaySong(args[0]);
            return true;
        }
    }

    public class Command_StopSong : Command
    {
        public Command_StopSong()
            : base("stopSong", "Stop the Audio Playback", UsageLevel.NORMAL)
        {

        }

        public override bool Invoke(List<string> args)
        {
            MEAudioManager.StopPlaying();
            return true;
        }
    }

    public class Command_PauseSong : Command
    {
        public Command_PauseSong()
            : base("pauseSong", "Pause the currently Playing Song", UsageLevel.NORMAL)
        {

        }

        public override bool Invoke(List<string> args)
        {
            MEAudioManager.PausePlaying();
            return true;
        }
    }

    public class Command_ResumeSong : Command
    {
        public Command_ResumeSong()
            : base("resumeSong", "Resume the currently Paused Song", UsageLevel.NORMAL)
        {

        }

        public override bool Invoke(List<string> args)
        {
            MEAudioManager.ResumePlaying();
            return true;
        }
    }

    #region Create Cube Command
    public class Command_CreateCube : Command
    {
        public Command_CreateCube()
            : base("createCube", "Creates a new Cube by default in front of the Camera. Usage x y z.", UsageLevel.NORMAL)
        {

        }

        public override bool Invoke(List<string> args)
        {
            Vector3 position;

            //We don't have enough arguments, so we create the Cube
            //in front of the Camera
            if (args.Count < 3)
            {
                MEBaseEntity cube = new MEBaseEntity("Cube", MECameraManager.mActiveCamera.Parent.Position + (MECameraManager.mActiveCamera.Parent.Rotation.Forward * 5), Matrix.Identity);
                MERenderComponent cubePrimitive = new MERenderComponent(cube, PrimitiveShape.Cube);
                MESceneGraphManager.RootEntity.AddChildEntity(cube);
                return true;
            }

            ////We have just a Position
            if (args.Count == 3)
            {
                position.X = Parser.toFloat(args[0]);
                position.Y = Parser.toFloat(args[1]);
                position.Z = Parser.toFloat(args[2]);

                //Now create the Cube
                MEBaseEntity cube = new MEBaseEntity("Cube", position, Matrix.Identity);
                MERenderComponent cubePrimitive = new MERenderComponent(cube, PrimitiveShape.Cube);
                MESceneGraphManager.RootEntity.AddChildEntity(cube);
                return true;
            }
            return false;
        }
    }
    #endregion

    #region Create Sphere Command
    public class Command_CreateSphere : Command
    {
        public Command_CreateSphere()
            : base("createSphere", "Creates a new Sphere by default in front of the Camera. Usage x y z.", UsageLevel.NORMAL)
        {

        }

        public override bool Invoke(List<string> args)
        {
            Vector3 position;

            //We don't have enough arguments, so we create the Sphere
            //in front of the Camera
            if (args.Count < 3)
            {
                MEBaseEntity sphere = new MEBaseEntity("Sphere", MECameraManager.mActiveCamera.Parent.Position + (MECameraManager.mActiveCamera.Parent.Rotation.Forward * 5), Matrix.Identity);
                MERenderComponent cubePrimitive = new MERenderComponent(sphere, PrimitiveShape.Sphere);
                MESceneGraphManager.RootEntity.AddChildEntity(sphere);
                return true;
            }

            ////We have just a Position
            if (args.Count == 3)
            {
                position.X = Parser.toFloat(args[0]);
                position.Y = Parser.toFloat(args[1]);
                position.Z = Parser.toFloat(args[2]);

                //Now create the Cube
                MEBaseEntity sphere = new MEBaseEntity("Sphere", position, Matrix.Identity);
                MERenderComponent spherePrimitive = new MERenderComponent(sphere, PrimitiveShape.Sphere);
                MESceneGraphManager.RootEntity.AddChildEntity(sphere);
                return true;
            }
            return false;
        }
    }
    #endregion

    #region create Ship Command
    public class Command_CreateShip : Command
    {
        public Command_CreateShip()
            : base("createShip", "Creates a new Ship by default in front of the Camera. Usage x y z.", UsageLevel.NORMAL)
        {

        }

        public override bool Invoke(List<string> args)
        {
            Vector3 position;

            if (args.Count < 3)
            {
                MEBaseEntity ship = new MEBaseEntity("Ship", MECameraManager.mActiveCamera.Parent.Position + (MECameraManager.mActiveCamera.Parent.Rotation.Forward * 5), Matrix.Identity);
                MERenderComponent shipRenderComponent = new MERenderComponent(ship, "Content/Models/Ship");
                MESceneGraphManager.RootEntity.AddChildEntity(ship);
                return true;
            }

            ////We have just a Position
            if (args.Count == 3)
            {
                position.X = Parser.toFloat(args[0]);
                position.Y = Parser.toFloat(args[1]);
                position.Z = Parser.toFloat(args[2]);

                //Now create the Ship
                MEBaseEntity ship = new MEBaseEntity("Ship", position, Matrix.Identity);
                MERenderComponent shipRenderComponent = new MERenderComponent(ship, "Content/Models/Ship");
                MESceneGraphManager.RootEntity.AddChildEntity(ship);
                return true;
            }
            return false;
        }
    }
    #endregion
}
